// page/member/member.js
Page({
  data: {
      isHide: 0,
      thumb: '',
      nickname: '',
      mum:0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      var that = this;
      /**
      * 获取用户信息
      */
     
      var that = this;
      var app = getApp()
      var uid = wx.getStorageSync('uid');
  
      if (uid.length==0){
          var app = getApp()
          var that = this;
          wx.login({
              success: function (res) {
                  wx.request({
                      url: app.globalData.host + '&g=App&m=Index&a=login',
                      data: { code: res.code },
                      header: {
                          'content-type': 'application/json'
                      },
                      success: function (res1) {
                          var session_key = res1.data.session_key
                          var openid = res1.data.openid
                          wx.getUserInfo({
                              success: function (res) {
                                  var userInfo = res.userInfo
                                  var adheadimg = userInfo.avatarUrl
                                  var adnickName = userInfo.nickName
                                  var encryptedData = res.encryptedData
                                  var iv = res.iv
                                  wx.request({
                                      url: app.globalData.host + '&g=App&m=Index&a=userinfo', //仅为示例，并非真实的接口地址
                                      data: {
                                          encryptedData: encryptedData, iv: iv, sessionKey: session_key, scene: 0
                                      }, header: {
                                          'content-type': 'application/json'
                                      },
                                      success: function (res) {
                                          var uid = parseInt(res.data)
                                          wx.setStorageSync('uid', uid) // 存储
                                          wx.setStorageSync('openid', openid) // 存储
                                          wx.setStorageSync('img', adheadimg) // 存储
                                          wx.setStorageSync('name', adnickName) // 存储
                                          wx.request({
                                              url: app.globalData.host + '&g=App&m=Member&a=member', //仅为示例，并非真实的接口地址
                                              data: { uid: uid },
                                              header: {
                                                  'content-type': 'application/json'
                                              },
                                              success: function (res) {
                                                  that.setData({
                                                      thumb: adheadimg,
                                                      nickname: adnickName,
                                                      isHide: 1,
                                                  })
                                              }
                                          })
                                      }
                                  })
                              }
                          })
                      }
                  })
              }
          })
      }else{
          var userface = wx.getStorageSync('img');
          var username = wx.getStorageSync('name');
          wx.request({
              url: app.globalData.host + '&g=App&m=Member&a=member', //仅为示例，并非真实的接口地址
              data: { uid: uid },
              header: {
                  'content-type': 'application/json'
              },
              success: function (res) {
                  that.setData({
                      isHide: 1,
                      thumb: userface,
                      mum: res.data.status,
                      nickname: username
                  })
              }
          })
      }

              
  },

  onShow: function () {
    var that = this;
    /**
    * 获取用户信息
    */
    var app = getApp()
    var uid = wx.getStorageSync('uid');
    wx.request({
      url: app.globalData.host + '&g=App&m=Member&a=member', //仅为示例，并非真实的接口地址
      data: { uid: uid },
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        that.setData({
          mum: res.data.status,
        })
      }
    })
    wx.removeStorage({
      key: 'orderTab',
      success: function (res) {

      }
    })
  },
  openOrder: function (e) {
    wx.setStorage({
      key: 'orderTab',
      data: e.currentTarget.dataset.id,
    })
  }
})